A magnetometer is capable of sensing geomagnetism, measuring a magnetic vector and determining an orientation of a device. However, a magnetometer is susceptible to the influence of the external magnet line of force including hard iron and soft iron. In this case, the trace of a magnetic vector changes, and the accuracy of data provided is affected. Then, the alignment of the hard iron and soft iron is required, but even after the alignment, the trace of the magnetic vector is not rolled back to the horizontal plane, so an inclination angle needs to be compensated.
After performing inclination angle compensation for a magnetometer, the trace of a magnet vector may be rolled back to the horizontal. An orientation ψ (that is, an included angle between the magnetic north direction and a component of a magnetic vector of the magnetometer on the horizontal S which is determined by the acceleration of gravity) may be calculated by the operation between a pitch angle θ and a roll angle φ that are obtained through the calculation of a trigonometric function by using the coordinate system of an accelerometer and the coordinate system of a magnetometer. Therefore, according to the measurement precision of a pitch angel θ and a roll angle φ as well as a geomagnetic inclination angle δ (that is, an included angle between a magnetic vector and the horizontal S), it is possible to determine the deviation Δψ of an orientation ψ so as to correct the orientation ψ, so that the accuracy of data provided by a magnetometer is improved.
In the method in the prior art for correcting an orientation of a magnetometer, an included angle between the magnetic vector that is measured by a magnetometer before being corrected and the horizontal S is used as δ corresponding to a current position of a device, and the δ is used to determine the deviation Δψ of the orientation so as to correct the orientation ψ.
During the process of correcting an orientation of a magnetometer, the inventor finds that the prior art has the following drawback: because the magnetometer is inaccurate before being corrected, the included angle δ between the magnetic vector that is measured by the magnetometer before being corrected and the horizontal S is also inaccurate, so using the inaccurate δ to calculate the deviation Δψ of the orientation and using the rough Δψ to correct the orientation may generate a false correction result and lead to inaccurate measurement of the magnetometer.